From 8628dbeb0d10896dc54bdc44e46697b1ed52d865 Mon Sep 17 00:00:00 2001 From: mcarton Date: Fri, 15 Jan 2016 15:51:28 +0100 Subject: [PATCH] Use .is_empty() where appropriate MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fix all of Clippy’s len_zero warnings. --- src/cargo/core/registry.rs | 2 +- src/cargo/core/resolver/mod.rs | 12 ++++++------ src/cargo/ops/cargo_clean.rs | 2 +- src/cargo/ops/cargo_compile.rs | 2 +- src/cargo/ops/cargo_doc.rs | 2 +- src/cargo/ops/cargo_generate_lockfile.rs | 2 +- src/cargo/ops/cargo_install.rs | 4 ++-- src/cargo/ops/cargo_rustc/context.rs | 2 +- src/cargo/ops/cargo_rustc/fingerprint.rs | 4 ++-- src/cargo/ops/cargo_rustc/job_queue.rs | 4 ++-- src/cargo/ops/cargo_test.rs | 4 ++-- src/cargo/sources/path.rs | 2 +- src/cargo/sources/registry.rs | 2 +- src/cargo/util/dependency_queue.rs | 2 +- src/cargo/util/errors.rs | 2 +- src/cargo/util/toml.rs | 2 +- tests/support/mod.rs | 4 ++-- tests/support/registry.rs | 2 +- 18 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/cargo/core/registry.rs b/src/cargo/core/registry.rs index d9daa1c94..60a82d300 100644 --- a/src/cargo/core/registry.rs +++ b/src/cargo/core/registry.rs @@ -295,7 +295,7 @@ impl<'cfg> Registry for PackageRegistry<'cfg> { fn query(&mut self, dep: &Dependency) -> CargoResult> { let overrides = try!(self.query_overrides(dep)); - let ret = if overrides.len() == 0 { + let ret = if overrides.is_empty() { // Ensure the requested source_id is loaded try!(self.ensure_loaded(dep.source_id(), Kind::Normal)); let mut ret = Vec::new(); diff --git a/src/cargo/core/resolver/mod.rs b/src/cargo/core/resolver/mod.rs index 5e2dc39a0..ceb4b4afd 100644 --- a/src/cargo/core/resolver/mod.rs +++ b/src/cargo/core/resolver/mod.rs @@ -453,7 +453,7 @@ fn activation_error(cx: &Context, candidates.sort_by(|a, b| { b.version().cmp(a.version()) }); - if candidates.len() > 0 { + if !candidates.is_empty() { msg.push_str("\nversions found: "); for (i, c) in candidates.iter().take(3).enumerate() { if i != 0 { msg.push_str(", "); } @@ -469,7 +469,7 @@ fn activation_error(cx: &Context, // update`. In this case try to print a helpful error! if dep.source_id().is_path() && dep.version_req().to_string().starts_with("=") && - candidates.len() > 0 { + !candidates.is_empty() { msg.push_str("\nconsider running `cargo update` to update \ a path dependency's locked version"); @@ -607,7 +607,7 @@ impl Context { (!use_default || prev.contains("default") || !has_default_feature) } - None => features.len() == 0 && (!use_default || !has_default_feature) + None => features.is_empty() && (!use_default || !has_default_feature) } } @@ -686,10 +686,10 @@ impl Context { // they should have all been weeded out by the above iteration. Any // remaining features are bugs in that the package does not actually // have those features. - if feature_deps.len() > 0 { + if !feature_deps.is_empty() { let unknown = feature_deps.keys().map(|s| &s[..]) .collect::>(); - if unknown.len() > 0 { + if !unknown.is_empty() { let features = unknown.connect(", "); bail!("Package `{}` does not have these features: `{}`", parent.package_id(), features) @@ -697,7 +697,7 @@ impl Context { } // Record what list of features is active for this package. - if used_features.len() > 0 { + if !used_features.is_empty() { let pkgid = parent.package_id(); self.resolve.features.entry(pkgid.clone()) .or_insert(HashSet::new()) diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index 7b3676b54..b14b4025d 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -22,7 +22,7 @@ pub fn clean(manifest_path: &Path, opts: &CleanOptions) -> CargoResult<()> { // If we have a spec, then we need to delete some packages, otherwise, just // remove the whole target directory and be done with it! - if opts.spec.len() == 0 { + if opts.spec.is_empty() { return rm_rf(&target_dir); } diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 43995c0d0..ce301935c 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -176,7 +176,7 @@ pub fn compile_pkg<'a>(root_package: &Package, vec![root_package.package_id()] }; - if spec.len() > 0 && invalid_spec.len() > 0 { + if !spec.is_empty() && !invalid_spec.is_empty() { bail!("could not find package matching spec `{}`", invalid_spec.connect(", ")) } diff --git a/src/cargo/ops/cargo_doc.rs b/src/cargo/ops/cargo_doc.rs index 8d843f31c..a6c38c295 100644 --- a/src/cargo/ops/cargo_doc.rs +++ b/src/cargo/ops/cargo_doc.rs @@ -18,7 +18,7 @@ pub fn doc(manifest_path: &Path, let mut lib_names = HashSet::new(); let mut bin_names = HashSet::new(); - if options.compile_opts.spec.len() == 0 { + if options.compile_opts.spec.is_empty() { for target in package.targets().iter().filter(|t| t.documented()) { if target.is_lib() { assert!(lib_names.insert(target.crate_name())); diff --git a/src/cargo/ops/cargo_generate_lockfile.rs b/src/cargo/ops/cargo_generate_lockfile.rs index f120a395f..fc2cdf430 100644 --- a/src/cargo/ops/cargo_generate_lockfile.rs +++ b/src/cargo/ops/cargo_generate_lockfile.rs @@ -43,7 +43,7 @@ pub fn update_lockfile(manifest_path: &Path, let mut registry = PackageRegistry::new(opts.config); let mut to_avoid = HashSet::new(); - if opts.to_update.len() == 0 { + if opts.to_update.is_empty() { to_avoid.extend(previous_resolve.iter()); } else { let mut sources = Vec::new(); diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs index dfe9ea361..0554fcd7b 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -312,7 +312,7 @@ pub fn uninstall(root: Option<&str>, } } - if bins.len() == 0 { + if bins.is_empty() { to_remove.extend(installed.get().iter().map(|b| dst.join(b))); installed.get_mut().clear(); } else { @@ -321,7 +321,7 @@ pub fn uninstall(root: Option<&str>, installed.get_mut().remove(bin); } } - if installed.get().len() == 0 { + if installed.get().is_empty() { installed.remove(); } } diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 716e04490..34f249b53 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -282,7 +282,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { } } } - assert!(ret.len() > 0); + assert!(!ret.is_empty()); Ok(ret) } diff --git a/src/cargo/ops/cargo_rustc/fingerprint.rs b/src/cargo/ops/cargo_rustc/fingerprint.rs index 66f0fb0dd..fcfc6c952 100644 --- a/src/cargo/ops/cargo_rustc/fingerprint.rs +++ b/src/cargo/ops/cargo_rustc/fingerprint.rs @@ -398,7 +398,7 @@ pub fn prepare_build_cmd<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) None => { let &(ref output, ref deps) = &cx.build_explicit_deps[unit]; - let local = if deps.len() == 0 { + let local = if deps.is_empty() { let s = try!(pkg_fingerprint(cx, unit.pkg)); LocalFingerprint::Precalculated(s) } else { @@ -440,7 +440,7 @@ pub fn prepare_build_cmd<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) let write_fingerprint = Work::new(move |_| { if let Some(output_path) = output_path { let outputs = state.outputs.lock().unwrap(); - if outputs[&key].rerun_if_changed.len() > 0 { + if !outputs[&key].rerun_if_changed.is_empty() { let slot = MtimeSlot(Mutex::new(None)); fingerprint.local = LocalFingerprint::MtimeBased(slot, output_path); diff --git a/src/cargo/ops/cargo_rustc/job_queue.rs b/src/cargo/ops/cargo_rustc/job_queue.rs index 6dea0a60d..30d6394c2 100644 --- a/src/cargo/ops/cargo_rustc/job_queue.rs +++ b/src/cargo/ops/cargo_rustc/job_queue.rs @@ -104,7 +104,7 @@ impl<'a> JobQueue<'a> { // and then immediately return. loop { while self.active < self.jobs { - if queue.len() > 0 { + if !queue.is_empty() { let (key, job, fresh) = queue.remove(0); try!(self.run(key, fresh, job, config, scope)); } else if let Some((fresh, key, jobs)) = self.queue.dequeue() { @@ -152,7 +152,7 @@ impl<'a> JobQueue<'a> { } } - if self.queue.len() == 0 { + if self.queue.is_empty() { Ok(()) } else { debug!("queue: {:#?}", self.queue); diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index e44374831..28a19077f 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -24,7 +24,7 @@ pub fn run_tests(manifest_path: &Path, let mut errors = try!(run_unit_tests(options, test_args, &compilation)); // If we have an error and want to fail fast, return - if errors.len() > 0 && !options.no_fail_fast { + if !errors.is_empty() && !options.no_fail_fast { return Ok(Some(CargoTestError::new(errors))) } @@ -38,7 +38,7 @@ pub fn run_tests(manifest_path: &Path, } errors.extend(try!(run_doc_tests(options, test_args, &compilation))); - if errors.len() == 0 { + if errors.is_empty() { Ok(None) } else { Ok(Some(CargoTestError::new(errors))) diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index 1cbead449..a6f5aede4 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -106,7 +106,7 @@ impl<'cfg> PathSource<'cfg> { let mut filter = |p: &Path| { let relative_path = util::without_prefix(p, &root).unwrap(); include.iter().any(|p| p.matches_path(&relative_path)) || { - include.len() == 0 && + include.is_empty() && !exclude.iter().any(|p| p.matches_path(&relative_path)) } }; diff --git a/src/cargo/sources/registry.rs b/src/cargo/sources/registry.rs index 9bce0dc25..dcfd74650 100644 --- a/src/cargo/sources/registry.rs +++ b/src/cargo/sources/registry.rs @@ -487,7 +487,7 @@ impl<'cfg> Registry for RegistrySource<'cfg> { let mut summaries = try!(self.summaries(dep.name())).iter().map(|s| { s.0.clone() }).collect::>(); - if try!(summaries.query(dep)).len() == 0 { + if try!(summaries.query(dep)).is_empty() { try!(self.do_update()); } } diff --git a/src/cargo/util/dependency_queue.rs b/src/cargo/util/dependency_queue.rs index 78d48232d..9db5d103c 100644 --- a/src/cargo/util/dependency_queue.rs +++ b/src/cargo/util/dependency_queue.rs @@ -99,7 +99,7 @@ impl DependencyQueue { /// `None` is returned then no packages are ready to be built. pub fn dequeue(&mut self) -> Option<(Freshness, K, V)> { let key = match self.dep_map.iter() - .find(|&(_, &(ref deps, _))| deps.len() == 0) + .find(|&(_, &(ref deps, _))| deps.is_empty()) .map(|(key, _)| key.clone()) { Some(key) => key, None => return None diff --git a/src/cargo/util/errors.rs b/src/cargo/util/errors.rs index d374cb50f..ef2fdeda5 100644 --- a/src/cargo/util/errors.rs +++ b/src/cargo/util/errors.rs @@ -142,7 +142,7 @@ pub struct CargoTestError { impl CargoTestError { #[allow(deprecated)] // connect => join in 1.3 pub fn new(errors: Vec) -> Self { - if errors.len() == 0 { + if errors.is_empty() { panic!("Cannot create CargoTestError from empty Vec") } let desc = errors.iter().map(|error| error.desc.clone()) diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index e7e910b3c..ff27b0247 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -138,7 +138,7 @@ pub fn to_manifest(contents: &[u8], match *toml { toml::Value::Table(ref table) => { for (k, v) in table.iter() { - add_unused_keys(m, v, if key.len() == 0 { + add_unused_keys(m, v, if key.is_empty() { k.clone() } else { key.clone() + "." + k diff --git a/tests/support/mod.rs b/tests/support/mod.rs index 91c9a6888..f57a283a0 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -370,7 +370,7 @@ impl Execs { } else { self.diff_lines(a, e, partial) }; - ham::expect(diffs.len() == 0, + ham::expect(diffs.is_empty(), format!("differences:\n\ {}\n\n\ other output:\n\ @@ -416,7 +416,7 @@ fn lines_match(expected: &str, mut actual: &str) -> bool { } } } - actual.len() == 0 || expected.ends_with("[..]") + actual.is_empty() || expected.ends_with("[..]") } struct ZipAll { diff --git a/tests/support/registry.rs b/tests/support/registry.rs index df0d5301a..2d4910edf 100644 --- a/tests/support/registry.rs +++ b/tests/support/registry.rs @@ -157,7 +157,7 @@ impl Package { let f = File::create(&dst).unwrap(); let a = Archive::new(GzEncoder::new(f, Default)); self.append(&a, "Cargo.toml", &manifest); - if self.files.len() == 0 { + if self.files.is_empty() { self.append(&a, "src/lib.rs", ""); } else { for &(ref name, ref contents) in self.files.iter() { -- 2.30.2